<?php
$projects=ProjectTable::getActiveProjects();

?><?php
//if(!isset($date))$date=MyDateTime::today()->tomysql();
$title1="projectreport".$month."/".$year;
$title2="";
$filename=$title1.".pdf";

  ?><?php
//============================================================+
// File name   : example_011.php
// Begin       : 2008-03-04
// Last Update : 2009-03-18
// 
// Description : Example 011 for TCPDF class
//               Colored Table
// 
// Author: Nicola Asuni
// 
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Colored Table
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */

require_once('../../tcpdf/config/lang/eng.php');
require_once('../../tcpdf/tcpdf.php');



// create new PDF document
$pdf = new TCPDF('L', PDF_UNIT, 'LEGAL', true, 'UTF-8', false);
$pdf->SetTitle($title1." ".$title2);
//$pdf->SetHeaderData("", 0, $title1, $title2);

//remove header & footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

//set some language-dependent strings
$pdf->setLanguageArray($l); 

// ----CONTENT START-----------------------------------------------------

// add a page
$pdf->AddPage();

//--------Header-------------------------

//quirino seal image
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
$pdf->Image('images/quirinoseal.jpg', 116, 23, 25, 25);

//Republic of the Philippines				
//PROVINCE OF QUIRINO				
//Cabarroguis				
//o0o
//
//Provincial Government of Quirino
$pdf->SetFont('helvetica', '', 12);
$content=array();
$content[]=array('  Republic of the Philippines');
$content[]=array('  PROVINCE OF QUIRINO');
$content[]=array('  Cabarroguis');
$content[]=array('  o0o');
$content[]=array('');
$content[]=array('Provincial Government of Quirino');
foreach($content as $row) {
	$pdf->Cell(0, 6, $row[0], '', 0, 'C');
	$pdf->Ln();
	}

//--------------body-------------------
//--------------Table header-------------------
$w=array(20,15,15,20,20,15,15,15,15,15,15,15,15,15,15,15,15);

$pdf->SetFont('helvetica', '', 9);
$content=array();
$content[]=array(
  "Project"
  ,"Code"
  ,"Project"
  ,"Category"
  ,"Contractor"
  ,"Contract"
  ,"Total "
  ,"Computed "
  ,"# Days"
  ,"Date "
  ,"Date "
  ,"Release "
  ,"Releases"
  ,""
  ," "
  ,"Total "
  ,"Total "
  );
foreach($content as $row) {
	$pdf->Cell($w[0], 6, $row[0], 'TLR', 0, 'C');
	$pdf->Cell($w[1], 6, $row[1], 'TR', 0, 'C');
	$pdf->Cell($w[2], 6, $row[2], 'TR', 0, 'C');
	$pdf->Cell($w[3], 6, $row[3], 'TR', 0, 'C');
	$pdf->Cell($w[4], 6, $row[4], 'TR', 0, 'C');
	$pdf->Cell($w[5], 6, $row[5], 'TR', 0, 'C');
	$pdf->Cell($w[6], 6, $row[6], 'TR', 0, 'C');
	$pdf->Cell($w[7], 6, $row[7], 'TR', 0, 'C');
	$pdf->Cell($w[8], 6, $row[8], 'TR', 0, 'C');
	$pdf->Cell($w[9], 6, $row[9], 'TR', 0, 'C');
	$pdf->Cell($w[10], 6, $row[10], 'TR', 0, 'C');
	$pdf->Cell($w[11], 6, $row[11], 'TR', 0, 'C');
	$pdf->Cell($w[12], 6, $row[12], 'TR', 0, 'C');
	$pdf->Cell($w[13], 6, $row[13], 'TR', 0, 'C');
	$pdf->Cell($w[14], 6, $row[14], 'TR', 0, 'C');
	$pdf->Cell($w[15], 6, $row[15], 'TR', 0, 'C');
	$pdf->Cell($w[16], 6, $row[16], 'TR', 0, 'C');
	$pdf->Ln();
	}

$pdf->SetFont('helvetica', '', 9);
$content=array();
$content[]=array(
  "Name"
  ,""
  ,"Cost"
  ,""
  ,""
  ,"Amount"
  ,"Contract"
  ,"Overhead"
  ,"to"
  ,"Start"
  ,"End"
  ,"Date"
  ,""
  ,"Disbursements"
  ,""
  ,"Release"
  ,""
  );
foreach($content as $row) {
	$pdf->Cell($w[0], 6, $row[0], 'LR', 0, 'C');
	$pdf->Cell($w[1], 6, $row[1], 'R', 0, 'C');
	$pdf->Cell($w[2], 6, $row[2], 'R', 0, 'C');
	$pdf->Cell($w[3], 6, $row[3], 'R', 0, 'C');
	$pdf->Cell($w[4], 6, $row[4], 'R', 0, 'C');
	$pdf->Cell($w[5], 6, $row[5], 'R', 0, 'C');
	$pdf->Cell($w[6], 6, $row[6], 'R', 0, 'C');
	$pdf->Cell($w[7], 6, $row[7], 'R', 0, 'C');
	$pdf->Cell($w[8], 6, $row[8], 'R', 0, 'C');
	$pdf->Cell($w[9], 6, $row[9], 'R', 0, 'C');
	$pdf->Cell($w[10], 6, $row[10], 'R', 0, 'C');
	$pdf->Cell($w[11], 6, $row[11], 'R', 0, 'C');
	$pdf->Cell($w[12], 6, $row[12], 'R', 0, 'C');
	$pdf->Cell($w[13], 6, $row[13], 'R', 0, 'C');
	$pdf->Cell($w[14], 6, $row[14], 'R', 0, 'C');
	$pdf->Cell($w[15], 6, $row[15], 'R', 0, 'C');
	$pdf->Cell($w[16], 6, $row[16], 'R', 0, 'C');
	$pdf->Ln();
	}

$content=array();
$content[]=array(
  ""
  ,""
  ,""
  ,""
  ,""
  ,""
  ,"Amount"
  ," "
  ,"Complete"
  ,""
  ,""
  ," "
  ,""
  ,""
  ,"  Balance"
  ," "
  ,"Disbursement"
  );
foreach($content as $row) {
	$pdf->Cell($w[0], 6, $row[0], 'BLR', 0, 'C');
	$pdf->Cell($w[1], 6, $row[1], 'BR', 0, 'C');
	$pdf->Cell($w[2], 6, $row[2], 'BR', 0, 'C');
	$pdf->Cell($w[3], 6, $row[3], 'BR', 0, 'C');
	$pdf->Cell($w[4], 6, $row[4], 'BR', 0, 'C');
	$pdf->Cell($w[5], 6, $row[5], 'BR', 0, 'C');
	$pdf->Cell($w[6], 6, $row[6], 'BR', 0, 'C');
	$pdf->Cell($w[7], 6, $row[7], 'BR', 0, 'C');
	$pdf->Cell($w[8], 6, $row[8], 'BR', 0, 'C');
	$pdf->Cell($w[9], 6, $row[9], 'BR', 0, 'C');
	$pdf->Cell($w[10], 6, $row[10], 'BR', 0, 'C');
	$pdf->Cell($w[11], 6, $row[11], 'BR', 0, 'C');
	$pdf->Cell($w[12], 6, $row[12], 'BR', 0, 'C');
	$pdf->Cell($w[13], 6, $row[13], 'BR', 0, 'C');
	$pdf->Cell($w[14], 6, $row[14], 'BR', 0, 'C');
	$pdf->Cell($w[15], 6, $row[15], 'BR', 0, 'C');
	$pdf->Cell($w[16], 6, $row[16], 'BR', 0, 'C');
	$pdf->Ln();
	}

//--------------Table body-------------------
$content=array();
foreach($projects as $project){ 
  $content[]=array(
    $project["name"],
    $project["code"],
    $project["project_cost"],
    "",
    "",
    "",
    $project["total_bid_amount"],
    $project["computed_overhead"],
    $project["days_to_complete"],
    $project["start_date"],
    $project["end_date"],
    "",
    "",
    "",
    "",
            "",
            "",
            "",
            "",
    );
 foreach($project->getContracts() as $contract)
 { 
    $content[]=array(
      "",
      "",
      "",
      $contract["category"],
      $contract["contractor"],
      $contract["bid_amount"],
      "",
      "",
      "",
      "",
      "",
      "",
      "",
      "",
      $contract["bid_amount"]-$contract["total_release
      $contract["total_release"],
      $contract["total_disbursement"],
      );

       foreach($contract->getDisbursements() as $disbursement)
       { 
          $content[]=array(
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            $disbursement["date"],
            $disbursement["release_amount"],
            $disbursement["disbursement_amount"],
            "",
            "",
            "",
            );


       } 
 } 
} 

foreach($content as $row) {
	$pdf->Cell($w[0], 6, $row[0], 'LR', 0, 'C');
	$pdf->Cell($w[1], 6, $row[1], 'R', 0, 'C');
	$pdf->Cell($w[2], 6, $row[2], 'R', 0, 'R');
	$pdf->Cell($w[3], 6, $row[3], 'R', 0, 'C');
	$pdf->Cell($w[4], 6, $row[4], 'R', 0, 'C');
	$pdf->Cell($w[5], 6, $row[5], 'R', 0, 'R');
	$pdf->Cell($w[6], 6, $row[6], 'R', 0, 'R');
	$pdf->Cell($w[7], 6, $row[7], 'R', 0, 'R');
	$pdf->Cell($w[8], 6, $row[8], 'R', 0, 'C');
	$pdf->Cell($w[9], 6, $row[9], 'R', 0, 'C');
	$pdf->Cell($w[10], 6, $row[10], 'R', 0, 'C');
	$pdf->Cell($w[11], 6, $row[11], 'R', 0, 'C');
	$pdf->Cell($w[12], 6, $row[12], 'R', 0, 'R');
	$pdf->Cell($w[13], 6, $row[13], 'R', 0, 'R');
	$pdf->Cell($w[14], 6, $row[14], 'R', 0, 'R');
	$pdf->Cell($w[15], 6, $row[15], 'R', 0, 'R');
	$pdf->Cell($w[16], 6, $row[16], 'R', 0, 'R');
	$pdf->Ln();
	}



//Close and output PDF document
if($download)
  $pdf->Output($filename, 'D');
else  
  $pdf->Output($filename, 'I');

//============================================================+
// END OF FILE                                                 
//============================================================+

?>
